package com.ssh.manager.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.ssh.common.util.Page;
import com.ssh.dao.IDao;
import com.ssh.entity.Brand;
import com.ssh.entity.Company;
import com.ssh.manager.BrandManager;

@Service
public class BrandManagerImpl implements BrandManager {
	@Override
	public Brand getBrandById(Long brandId) {
		return daoImpl.getDomain(Brand.class, brandId);
	}

	@Resource
	private IDao daoImpl;

	@Override
	public Brand saveOrUpdateBrand(Brand brand) {
		return daoImpl.saveOrUpdateDomain(brand);
	}

	@Override
	public void findBrandByPage(Page page, String isDesc) {
		String sql = "select count(*) from Brand where del!=1";
		int companySum = daoImpl.countAll(sql, null);
		page.setTotalCount(new Long(companySum));
		page.countTotalPageNum();
		
		sql = "from Brand where del!=1 order by createDate "+isDesc;
		List<Brand> brands = (List<Brand>)daoImpl.findListBySql(sql, new Object[]{}, false, true, false, page.getNumberPerPage()*(page.getCurPageNum()-1), page.getNumberPerPage());
		page.setPageData(brands);
	}

	@Override
	public List<Brand> getAllBrand() {
		String sql = "from Brand where del!=1 order by createDate desc";
		List<Brand> brands = (List<Brand>)daoImpl.findListBySql(sql, new Object[]{}, false, true, false, 0, -1);
		return brands;
	}
}
